package com.example.shaoying.yuejian.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.Adapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.shaoying.yuejian.R;
import com.example.shaoying.yuejian.common.Constants;
import com.example.shaoying.yuejian.javabean.DingDan;
import com.example.shaoying.yuejian.javabean.UserGuanzhu;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2017/10/11 0011.
 */

public class UserDingdanAdapter extends Adapter {

    private List<DingDan> userGuanzhus;
    private Context context;
    private LayoutInflater layoutInflater;
    public UserDingdanAdapter(Context context, List<DingDan> userGuanzhus){
        this.context=context;
        this.userGuanzhus=userGuanzhus;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View itemView=LayoutInflater.from(context).inflate(R.layout.dingdanitem,viewGroup,false);
        UserGuanZhuViewHolder holder=new UserGuanZhuViewHolder(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {

        UserGuanZhuViewHolder userGuanZhuViewHolder= (UserGuanZhuViewHolder) viewHolder;
        DingDan guanzhu=userGuanzhus.get(position);



        String guanzhu_pic= Constants.PIC_URL+guanzhu.getThumb();
        userGuanZhuViewHolder.name.setText(guanzhu.getName());
        userGuanZhuViewHolder.dingdan.setText(guanzhu.getId());
        userGuanZhuViewHolder.price.setText(guanzhu.getPrice());
        userGuanZhuViewHolder.time.setText(guanzhu.getUpdate_time());
        Picasso.with(context).load(guanzhu_pic).into(userGuanZhuViewHolder.photo);

    }

    @Override
    public int getItemCount() {
        return userGuanzhus.size();
    }


    public class UserGuanZhuViewHolder extends RecyclerView.ViewHolder{


        public TextView name,dingdan,price,time;
        public ImageView photo;
        public View itemView;

        public UserGuanZhuViewHolder(View itemView) {
            super(itemView);
            this.itemView=itemView;
            name= (TextView) itemView.findViewById(R.id.name);
            dingdan= (TextView) itemView.findViewById(R.id.dingdan);
            time= (TextView) itemView.findViewById(R.id.time);
            price= (TextView) itemView.findViewById(R.id.price);
            photo= (ImageView) itemView.findViewById(R.id.photo);
        }
    }
}
